<?php
session_start();
include 'db.php';
	
	function Send_Mail($att){
		$to      = $att['to'];
		$subject = $att['subject'];
		$message = $att['message'];
		$headers = 'From: ' .$att['repto']. "\r\n" .
			'Reply-To:' .$att['repto']. "\r\n" .
		$headers .= 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		$res = mail($to, $subject, $message, $headers);
		if($res){
			return true;
		}else{
			return false;
		}
	}

	if($_SESSION['req_qses']){
		$getitems = mysql_query("SELECT * FROM items");
		$items = NULL;
		$total = 0;
		$items .= "
		<p>Customer Name: ".$_SESSION['req_name']."</p>
		<p>Email Address: ".$_SESSION['req_email']."</p>
		<p>Company: ".$_SESSION['req_company']."</p>
		<p>Contact Number: ".$_SESSION['req_contact']."</p>
		<table width=\"100%\" border=\"1\">
			<tr>
					<td><strong>Item Description</strong></td>
					<td><strong>Quantity</strong></td>
					<td><strong>Item Price</strong></td>
					<td><strong>Amount</strong></td>
				</tr>
		";
		while($geti = mysql_fetch_array($getitems)){
			if($geti['itemId'] == $_SESSION['item_'.$geti['itemId']]){
				$amount = $geti['itemPrice'] * $_SESSION['item_'.$geti['itemId']."_qty"];
				$total = $total+$amount;
				$items .= "
				
				<tr>
					<td>".$geti['itemDesc']."</td>
					<td>".$_SESSION['item_'.$geti['itemId']."_qty"]."</td>
					<td>".$geti['itemPrice']."</td>
					<td>".$amount."</td>
				</tr>
				";
			}
		}
		$items .= "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td><strong>Amount: ".number_format($total,2,".","")." AED</strong></td></tr></table>";
		$data = array(
		"to" => "juluis@gtechme.com",
		"subject" => "Ledlamps Customer Request Quote",
		"repto" => $_SESSION['req_email'], 
		"message" => $items
		);
		if(Send_Mail($data)){
			$_SESSION['req_name'] = NULL;
			$_SESSION['req_email'] = NULL;
			$_SESSION['req_company'] = NULL; 
			$_SESSION['req_contact'] = NULL;
			$_SESSION['req_qses'] = NULL; 
			
			header('location:thankyou.php?ac=rq');
		}
	}
?>